<?php


namespace App\Common;


class Util
{
    public static function json_encode_unicode($arr)
    {
        //不转义中文和反斜杠/
        return json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    }

    public static function xml2arr($xml){
        $xml = (array)$xml;
        foreach($xml as $k => $v){
            if(is_array($v) || is_object($v)){
                $xml[$k] = self::xml2arr($v);
            }
        }
        return $xml;
    }

    /**
     * 将xml转为array，微信支付代码
     * @param string $xml
     */
    public static function FromXml($xml)
    {
        //将XML转为array
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $values;
    }
}
